import tkinter
import queue
from .TkinterBinds import *
from .TkinterConfigs import *
from .TkinterControls import *
DATA_QUEUE = queue.Queue()

class TkinterApp:
    def __init__(self, master):
        self.Master = master
        self._InitCreareUi()
        self._InitLayout()
        self._InitThread()
        self._InitCommand()
        self._StartQueueProcessing()

    def _InitCreareUi(self):
        self._InitUi()
        self.CreateUI()

    def _InitLayout(self):
        pass

    def _InitThread(self):
        pass

    def _InitThreadPool(self):
        pass

    def _InitCommand(self):
        self.command_1 = lambda : print("lambda 表达式")

    def _InitUi(self):
        self.Master.title("简单的Tkinter GUI")
        self.Master.minsize(width=500, height=500)
        self.Master.maxsize(width=500, height=500)

    def CreateUI(self):
        self.Create_BUTTON()
    
    def Create_BUTTON(self):

        
        self.Button_1 = tkinter.Button(master=self.Master)
        # 使用ttk.Button替换tkinter.Button
        
        self.Button_1.pack(side=tkinter.LEFT)
        command = lambda event : [print("Button_1 clicked"),
                                  print(f"Event : {event}"),
                                  value := "海象表达式赋值!",
                                  print(value),
                                  self.command_1()
                                  ]
        
        Tkinter事件绑定器.绑定点击事件(self.Button_1,command=command)
        Tkinter属性修改器.修改文本(self.Button_1, text="按钮")
        Tkinter属性修改器.修改位置(self.Button_1, 150, 20)
        Tkinter属性修改器.修改字体(self.Button_1,font_name="微软雅黑",font_size=20)
    
    def _StartQueueProcessing(self):
        """启动定时器处理队列中的数据"""
        def _ProcessQueue():
            """处理队列中的数据并更新 GUI"""
            try:
                while True:
                    data = DATA_QUEUE.get_nowait()  # 尝试获取队列中的数据
            except queue.Empty:
                pass
            
            # 定时调用 _ProcessQueue 函数
            self.Master.after(100, _ProcessQueue)
        _ProcessQueue()